package com.ll.wechat.user.fragment;

import org.jivesoftware.smackx.vcardtemp.packet.VCard;

import android.graphics.BitmapFactory;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ll.wechat.R;
import com.ll.wechat.base.app.User;
import com.ll.wechat.base.fragment.BaseFragment;
import com.ll.wechat.base.utils.widget.MyToast;
import com.ll.wechat.user.activity.UserInfoActivity;

/**
 * 微信tab第四
 * 
 * @ClassName: UserFragment
 * @author yeliangliang
 * @date 2015-8-7 下午4:09:45
 */
public class UserFragment extends BaseFragment implements OnClickListener {

	private TextView tv_name;
	private TextView tv_passName;
	private RelativeLayout rl_user;
	private ImageView img_head;

	@Override
	public int setRootViewId() {
		return R.layout.fragment_user;
	}

	@Override
	protected void initView(View rootView) {
		tv_name = (TextView) rootView.findViewById(R.id.tv_user_name);
		tv_passName = (TextView) rootView.findViewById(R.id.tv_user_passName);
		rl_user = (RelativeLayout) rootView.findViewById(R.id.rl_user);
		rl_user.setOnClickListener(this);
		img_head = (ImageView) rootView.findViewById(R.id.img_head);
	}

	@Override
	protected void initData() {
		tv_passName.setText("微信号：" + User.getInstance().getUserInfo().getUserPassName());
		tv_name.setText(User.getInstance().getUserInfo().getUserName());
		VCard vCard = new VCard();
		try {
			vCard.load(User.getInstance().getConnection());
		} catch (Exception e) {
			e.printStackTrace();
			MyToast.showToast(getActivity(), "头像加载失败");
		}
		byte[] b = vCard.getAvatar();
		if (!(b==null||b.length==0)) {
			
			img_head.setImageBitmap(BitmapFactory.decodeByteArray(b, 0, b.length));
		}

	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.rl_user:// 跳转用户信息页面
			showActivity(getActivity(), UserInfoActivity.class);
			break;

		default:
			break;
		}
	}

}
